#include <iostream>
#include <optional>
#include <vector>

std::optional<int> FindByIndex(std::vector<int> &v, int index)
{
    if (index < 0 || index >= v.size())
    {
        throw std::nullopt; // 空对象
    }
    return v[index];
}

int main()
{
    std::vector<int> v = {1, 2, 3, 4, 5};
    auto value = FindByIndex(v, 2);
    if (value)
    {
        std::cout << *value << std::endl;
    }
    else
    {
        std::cout << "没找到!\n" << std::endl;
    }
    return 0;
}